Robotics 1.0 Lesson Plan
Lesson 28: Build a bot - Coding and Debugging

Purpose: Write, test, debug, and refine the garbage sorting robot code while learning to troubleshoot sensor and actuator issues and document the final working flow.

No. of Classes

1 class (Duration: 1 hour 30 minutes; maximum of 4 students per group).

Materials Required

Circuit Playground Express (CPX), Crickit board, USB cable, 5v Battery

Rain sensor

Inductive proximity sensor

IR sensor

Stepper motor

Jumper wires

Foam board

Cups or containers for sorting bins

Screws, nuts, zip ties and tape for mounting

Prior Knowledge

Basic understanding of sensors and actuators used in earlier lessons

Familiarity with CPX and Crickit boards and basic wiring

Experience assembling simple robotic structures and mounting components

Exercises

Exercise 1:



Test the connection and working of various sensors and actuators. Use the reference code given below where needed.

  • Click here to view the code for rain sensor

  • Click here to view the code for Inductive Proximity sensor

  • Click here to view the code for Stepper motor

  • Exercise 2:



  • Use this given pseudocode as a reference and implement the code for the garbage sorter.


  • Test the garbage sorter for various use cases including adding wet waste, dry waste and various other combinations

  • Exercise 3:



  • Use this code to run the garbage sorter. Debug the code to make the garbage sorter work as intended.


  • Solution



  • Click here to view the solution video for Exercise 2 showing the working of the garbage sorter
  • Click here to view the code for Exercise 2
  • Click here to view the code explanation for Exercise 2
  • Click here to view the solution video for Exercise 3, explaining how to debug the code and fix the bugs in the code.
  • Teacher’s Instructions
    1. Explain that this lesson focuses on coding, testing, and debugging the garbage sorting robot, not on physical construction.
    2. Review the overall working logic of the garbage sorter using the reference flow or pseudocode.
    3. Guide students to test each sensor individually and verify that correct values are being read in the code.
    4. Discuss how sensor readings influence decision making in the program.
    5. Explain the importance of writing modular code using functions for sensors and actuators.
    6. Demonstrate common debugging techniques such as printing values, isolating code blocks, and testing one component at a time.
    7. Encourage students to test multiple scenarios, including mixed waste, repeated inputs, and unexpected objects.
    8. Help students identify and fix issues such as incorrect conditions, delays, timing problems, or motor misbehavior.
    9. Ask students to document the final working logic of their code using a flowchart or step-by-step explanation.
    10. If rain sensor, inductive proximity sensor and IR sensor gives values at the same time, how will you decide which action to execute?
    11. Can the CPX and Crickit keep track of how many items have been sorted in each category while the program is running? What happens to these counts when the board is reset or power is turned off? If the values are lost after a reset, how could you design the system so the robot remembers this information even after restarting?